package org.libarae.communication.request;

import org.libarae.communication.XmlParseException;
import org.w3c.dom.Document;

public abstract class Request {
	private int mType; //defined in communication.common.Type
	private String mAccessKey = null;
	private boolean isWebRequest;
	
	public Request(int type){
		this.mType = type;
	}	
	
	private String htmlHelperMessage;
	
	public boolean isWebRequest() {
		return isWebRequest;
	}
	
	public void setWebRequest(boolean isWebRequest) {
		this.isWebRequest = isWebRequest;
	}
	
	/**
	 * Sets a helper message to be set as a cookie by the server interface, used for the HTML client
	 * @param htmlHelperMessage
	 */
	public void setHtmlHelperMessage(String htmlHelperMessage) {
		this.htmlHelperMessage = htmlHelperMessage;
	}
	
	/**
	 * 
	 * @return the helper message to be set as a cookie for an HTML client
	 */
	public String getHtmlHelperMessage() {
		return htmlHelperMessage;
	}
	
	public abstract String createXML() throws XmlParseException;
	public abstract void decodeXML(Document document);
	
	/**
	 * Requests from a webt page will be in the form of POST 
	 * requests from a form. This method creates a POST style
	 * request of this Request type. This method should not 
	 * be needed in normal operation, but is useful for testing.
	 *  
	 * @return an HTTP POST version of this request
	 */
	public abstract String creatGET();
	
	/**
	 * Decodes an HTTP POST request into a Request object. 
	 * @param postMessage TODO
	 */
	public abstract void decodeGET(String postMessage);
	
	public int getType() {
		return mType;
	}

	public void setType(int type) {
		this.mType = type;
	}

	public String getAccessKey() {
		return mAccessKey;
	}

	public void setAccessKey(String mAccessKey) {
		this.mAccessKey = mAccessKey;
	}


}
